<?php 
	require_once("init.php");  
?>

<?php 
	if (isset($_POST["submitForm"])) {
	
		// Delete user's topic
		$qDeleteTopic = mysql_query("
			UPDATE topics 
			SET statusId = ".$statusDeleted."
			WHERE topicId = ".$_POST["topicId"]."
			AND userId = ".$_SESSION["userId"]."
		");
?>

<form id="delete-topic-success" class="dialog" method="post" target="_self" action="redirect.php?url=index.php">
	<fieldset>
    <h1>Topic deleted!</h1>
    <p align="center"><input class="submit" type="submit" name="submit" value="Continue" /></p>
  </fieldset>
</form>

<?php
	} else {
	
		$userId = 1;
		if (isset($_SESSION["userId"])) {
			$userId = $_SESSION["userId"];
		}
	
		$strCheckTopic = "
			SELECT topicId
			FROM topics
			WHERE topicId = ".$_GET["id"]."
		";
		if (isset($_SESSION["userId"])) {
			$strCheckTopic = $strCheckTopic."
				AND userId = ".$_SESSION["userId"]."
			";
		} else {
?>
<div id="delete-topic-fail" title="Oops!" class="panel">
	<p>Oops! You must be signed in to do this.</p>
</div>
<?php
			die("Oops! You must be signed in to do this.");
		}
		$qCheckTopic = mysql_query($strCheckTopic);
		
		// if topic cannot be found, display error message
		if (mysql_num_rows($qCheckTopic) == 0) {
?>

<div id="delete-topic-fail" title="Oops!" class="panel">
	<p>The topic cannot be found.</p>
</div>

<?php 
		} else {
?>

<form id="deleteTopicForm" class="dialog" method="post" action="deletetopic.php">
	<input type="hidden" name="submitForm" value="submitForm" />
	<input type="hidden" name="topicId" value="<?php print $_GET["id"]; ?>" />
	<fieldset>
    <h1>Delete this topic?</h1>
    <a class="button leftButton" type="cancel">Cancel</a>
    <a class="button blueButton" type="submit">Yes</a>
  </fieldset>
</form>

<?php
		}
	}
?>

<?php 
	require_once("end.php"); 
?>